<template>
  <div class="nav-header">
    <el-icon :size="30" class="icon" @click="handelFoldClick">
      <Fold v-if="isFold"></Fold>
      <Expand v-else></Expand>
    </el-icon>
    <!-- <el-icon :size="30" class="icon" @click="handelFoldClick"> /></el-icon> -->
    <div class="content">
      <div>
        <zhbread-crumb :breadcrumbs="breadcrumbs"></zhbread-crumb>
      </div>
      <div>
        <user-info></user-info>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import userInfo from './user-info.vue'
import { defineComponent, ref, computed } from 'vue'
import ZhbreadCrumb from '@/base-ui/breadcrumb/index'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'
export default defineComponent({
  name: 'navHeader',
  components: {
    userInfo,
    ZhbreadCrumb
  },
  emits: ['foldChange'],
  setup(props, { emit }) {
    const store = useStore()
    const route = useRoute()
    //
    const isFold = ref(false)
    const handelFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }
    //
    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const currentPath = route.path
      return pathMapBreadcrumbs(userMenus, currentPath)
    })
    //
    return {
      isFold,
      handelFoldClick,
      breadcrumbs
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  align-items: center;
  width: 100%;
  .content {
    flex: 1;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
.icon {
  cursor: pointer;
}
</style>
